# coding=utf-8
import allure
from common.assert_operator import *
from common.db import *
from common.read_yaml import *
from common.utils import Utils

string_assert = string_assert() # 字符串校验类
pact = Pact() # 契约校验类
execute_sql = sql() # sql集合
utils = Utils()
data = ReadYaml_By_Root_Dict("case/99_outside_api_test/02_bpm_outside_test/99_02_1_GetProcessInstanceInfo_GetProcessState.yml").get_yaml_data()  # 读取数据

@allure.feature('测试流程中心外部接口：通过业务id获取流程详情，获取流程状态')  # 测试报告显示测试功能
class Test_99_02_1_GetProcessInstanceInfo_GetProcessState():
    """
    测试接口：
    /api/flowinstance/approval/get-process-instance-info
    /api/flowinstance/approval/get-process-state
    """
    # 获取yml文件中[获取流程详情]的数据参数
    Params = data['获取流程详情']
    # 获取yml的title，并作为ids的值传给用例
    ids_list = jsonpath.jsonpath(Params, "$[*][0]")
    @pytest.mark.parametrize("title, param, expect", Params, ids=ids_list)
    def test_GetProcessInstanceInfo(self, user_login, title, param, expect):
        allure.dynamic.description(f"{param['用例描述']}")  # # 动态解析用例描述在测试报告中展示
        main = user_login.goto_Bpm_Outside_Api(param['用户'])
        resp = main.get_process_instance_info(param['请求体'])
        # 响应校验获取方式：开启fiddler，执行用例后，直接获取fiddler的响应body
        dict_assert(expect['响应校验'],resp.json())    # 结果断言

    # 获取yml文件中[获取流程详情_异常场景]的数据参数
    Params = data['获取流程详情_异常场景']
    # 获取yml的title，并作为ids的值传给用例
    ids_list = jsonpath.jsonpath(Params, "$[*][0]")
    @pytest.mark.parametrize("title, param, expect", Params, ids=ids_list)
    def test_GetProcessInstanceInfo_Abnormal(self, user_login, title, param, expect):
        allure.dynamic.description(f"{param['用例描述']}")  # # 动态解析用例描述在测试报告中展示
        main = user_login.goto_Bpm_Outside_Api(param['用户'])
        resp = main.get_process_instance_info(param['请求体'])
        dict_assert(expect['响应校验'],resp.json())    # 结果断言

    # 获取yml文件中[获取流程状态]的数据参数
    Params = data['获取流程状态']
    # 获取yml的title，并作为ids的值传给用例
    ids_list = jsonpath.jsonpath(Params, "$[*][0]")
    @pytest.mark.parametrize("title, param, expect", Params, ids=ids_list)
    def test_GetProcessState(self, user_login, title, param, expect):
        allure.dynamic.description(f"{param['用例描述']}")  # # 动态解析用例描述在测试报告中展示
        main = user_login.goto_Bpm_Outside_Api(param['用户'])
        resp = main.get_process_instance_info(param['请求体'])
        # 响应校验获取方式：开启fiddler，执行用例后，直接获取fiddler的响应body
        dict_assert(expect['响应校验'],resp.json())    # 结果断言

    # 获取yml文件中[获取流程状态_异常场景]的数据参数
    Params = data['获取流程状态_异常场景']
    # 获取yml的title，并作为ids的值传给用例
    ids_list = jsonpath.jsonpath(Params, "$[*][0]")
    @pytest.mark.parametrize("title, param, expect", Params, ids=ids_list)
    def test_GetProcessState_Abnormal(self, user_login, title, param, expect):
        allure.dynamic.description(f"{param['用例描述']}")  # # 动态解析用例描述在测试报告中展示
        main = user_login.goto_Bpm_Outside_Api(param['用户'])
        resp = main.get_process_instance_info(param['请求体'])
        dict_assert(expect['响应校验'],resp.json())    # 结果断言
